/**
 * 
 */
package edu.utsa.cs.cs4953_2012.abacus;

import java.awt.Button;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author mcvoid
 * 
 */
public class StatusPanel extends JPanel {
	/**
	 * Event handler for clicking a button.
	 * 
	 */
	private class ResetButtonHandler implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			if ("Reset Board".equals(e.getActionCommand())) {
				Board.getInstance().Reset();
				Program.content.repaint();
			}
		}
	}

	/**
	 * Required for Serializable interface.
	 */
	private static final long serialVersionUID = 5899981052755169447L;

	/**
	 * Shows the total value of the board.
	 */
	private JLabel value;

	/**
	 * Default Constructor
	 */
	public StatusPanel() {
		Button reset = new Button("Reset Board");
		reset.setActionCommand("Reset Board");
		reset.addActionListener(new ResetButtonHandler());
		value = new JLabel(Board.getInstance().getValue().toString());

		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		add(value);
		add(reset);
	}

	/**
	 * The routine that is called by the system whenever the window repaints.
	 * 
	 * @param g
	 *            The graphics device being used by the window.
	 */
	@Override
	public void paintComponent(Graphics g) {
		g.clearRect(0, 0, getWidth(), getHeight());
		value.setText(Board.getInstance().getValue().toString());
	}
}
